Same for me, Mac Studio M2
Post
Replies
Boosts
Views
Activity
I found this to be working... is there a simpler way to achieve this?
This takes the translation3D we get from the drag gesture, records an initialOffset (otherwise my entity jumps upward, because it has its origin in the bottom center). then it rotates the translation vector around x such that y becomes 0. Finally it converts it into the coordinate system of the entity's parent.
Phew...
.gesture(DragGesture()
.targetedToAnyEntity()
.onChanged { value in
if initialDragOffset == .zero {
// Calculate the initial drag offset at the beginning of the drag
let startLocation = value.convert(value.startLocation3D, from: .local, to: value.entity.parent!)
initialDragOffset = value.entity.position - SIMD3<Float>(startLocation.x, startLocation.y, startLocation.z)
}
let translation3D = value.translation3D
// Rotate the drag vector such that its y-component becomes zero
let theta = atan2(translation3D.y, translation3D.z)
let cosTheta = cos(theta)
let sinTheta = sin(theta)
let rotatedX = translation3D.x
let rotatedY = 0 // Force y to be zero
let rotatedZ = theta >= 0 ? translation3D.y * sinTheta + translation3D.z * cosTheta : translation3D.z * cosTheta - translation3D.y * sinTheta
let rotatedVector = SIMD3<Float>(Float(rotatedX), 0, Float(rotatedZ))
var newLocation3D = value.startLocation3D
newLocation3D.x += Double(rotatedVector.x)
newLocation3D.y += Double(rotatedVector.y)
newLocation3D.z += Double(rotatedVector.z)
// Convert the 3D location of the drag gesture to the entity's parent coordinate space
let dragLocation = value.convert(newLocation3D, from: .local, to: value.entity.parent!)
var newPosition = SIMD3<Float>(dragLocation.x, dragLocation.y, dragLocation.z) + initialDragOffset
// don't modify y coordinate so that model remains standing on ground
newPosition.y = value.entity.position.y
// Set the entity's position to the new position
value.entity.position = newPosition
}
.onEnded({ value in
initialDragOffset = .zero
}))
Also found this, and reported it as FB.
Another problem is that my AreaMarks also go out of the visible area. So my more general question is to Apple: how does one deal with marks that are outside of the desired chart ranges for the x and y axes?
I found that LineMark and AreaMark have a series parameter by which a series can be grouped. By doing that I can set a static foregroundStyle for my percentile area marks while using the data-based foreground styles for the actual data line marks.
I found that instead of parsing the encapsulated AxisValue you can transform it into the orginal value.
For an Int I am doing it so:
.chartXAxis() { AxisMarks(values: .stride(by: 1)) { let month = $0.as(Int.self)! } }
The .stride(by: 1) overrides the automatic selection of marks.
I was told that the function to generate an Xcode project predates support for resources and thus doesn’t add the building of resource bundles.
I found you can use
#if SWIFT_PACKAGE
	 let resourceBundle = Bundle.module
#endif
This define is present when building the code via SwiftPM.
Still not available in Beta 5?
This following code is using a List, so the highlight is working as expected, but I cannot scroll to a specific item.
struct ContentView: View {
let timezones = TimeZone.knownTimeZoneIdentifiers.map { TimeZone(identifier: $0)! }
var body: some View {
let continents = Set(timezones.compactMap { $0.continent }).sorted()
List {
ForEach(continents, id: \.self) { continent in
let continentTZ = timezones.filter { $0.continent == continent}
Section(header: HeaderView(title: continent)) {
ForEach(continentTZ) { timezone in
Button(action: {
}) {
TimeZoneCell(timezone: timezone)
}
}
}
}
}.navigationBarTitle(Text("Time Zones"), displayMode: .inline)
}
}